Repository navigation
fix: size a blob whose content is a complete replacement from the replacement - #288
PabloPardoGarcia wants to merge 2 commits into
Conversation
…lacement A native blob part whose content is a complete replacement now takes byte_size from it, and its mime when the part has no valid mime_type, per the rius-semconv media contract. The serializer strips a blob's base64 content to a replacement before the exporter rebuilds the part, so a blob set through the SDK's own setters lost its byte_size; bytes and base64 now store alike.
Automated reviewSummary. One blocker. Blocker: a long digit run in a replacement raises inside the exporter and drops the batch
Since Python 3.11, v = "[stripped unknown " + "9" * 4301 + " bytes]"
span.set_attribute("gen_ai.input.messages", json.dumps([{"role": "user", "parts": [{"type": "blob", "content": v}]}])) # dropped
span.set_attribute("output", json.dumps({"mime_type": v, "data": "QUJD"})) # dropped
span.set_attribute("output", json.dumps({"type": "image", "source_type": "base64", "data": v})) # droppedEvery one of these logs Suggestion: if digits:
significant = size.lstrip("0") or "0"
byte_size = int(significant) if len(significant) <= 16 else None # 2^53 - 1 has 16 digitsAdd a test that sets these three attributes and asserts the spans export, plus one for the 5000-zeros case giving 8. The reference generator has the same line (rius-semconv#115), so the fix there and here should land together. Suggestion: a blob set as an object and as a JSON string can still store differently
The data URL rows predate this PR. The cause is in the contract (rule (e) vs Nits
|
int() refuses a string over 4300 digits, leading zeros included, and is_replacement now parses the size. The strip calls it on sibling strings inside the export chain, so a replacement with a long digit run in a message, an output or a mime key raised ValueError and the whole batch was dropped. Drop leading zeros first, and treat a run with more significant digits than 2^53 - 1 has as an unknown size without converting it. Re-vendor the contract, whose new examples pin 5000 zeros then 8 (byte_size 8), 5000 nines and a size past int64 (no byte_size).
|
Addressed in 4260f88.
|
|
Landed through #289, together with the rius-semconv v1.13.0 sync. |
This implements the rius-semconv rule from glassflow/rius-semconv#115. A native blob part whose
contentis a complete replacement takes itsbyte_sizefrom the replacement. The size is omitted when it is unknown or larger than 2^53 - 1. The part's validmime_typecomes first, and the replacement's mime fills in when the part has none.Why it matters here
The SDK's serializer strips a blob's base64
contentto a replacement ([stripped image/png 8 bytes]) before the exporter rebuilds the part. So any blob set through the SDK's own setters lost itsbyte_size, even when it was sent as base64. Bytes, which become[stripped unknown 8 bytes], lost it too. Now both store the same part.Changes
src/rius/_media.py(parse_replacement,native_part)d826d04, the feat: take the main agent identity into rius.main_agent.*, and version the agent at both scopes #115 branch head.tests/test_media_parts.pylists inputs for the new contract examples.tests/test_byte_objects.pyadds an end-to-end test: bytes and base64 set through the SDK store the same blob withbyte_size: 8.Long digit runs
int()refuses a string over 4300 digits, leading zeros included, andis_replacementnow parses the size. The strip calls it on sibling strings inside the export chain, so a replacement with a long digit run in a message, an output or a mime key raisedValueErrorand dropped the whole batch.parse_replacementnow drops leading zeros first and treats more than 16 significant digits as an unknown size without converting them, the same as the reference.tests/test_byte_objects.pysends three such attributes throughinit's real export chain (a blob'scontent, amime_typesibling, an Anthropic-styledata) and checks each span is exported, plus a blob of 5000 zeros then 8 stored withbyte_size: 8. All four failed before the fix (span export failed: the export chain raised ValueError).Checks
ruff check,ruff format --check,mypyandpytestpass (2927 passed, 22 skipped, 1 xfailed)._media.pychange, the contract examples and the end-to-end test fail.Merge note: squash-merge glassflow/rius-semconv#115 first. Then re-sync this branch from semconv main (
scripts/sync-semconv-fixtures.sh). OnlySOURCEand the vendored headers should change.Related: RIUS-1875